using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraMove : MonoBehaviour
{
    const float fluencedis = 0.01f;
    private Transform target;
    private Camera mcam;
    // Start is called before the first frame update
    void Start()
    {
        target = GameObject.FindGameObjectWithTag("Player").transform;
        transform.position = new Vector3(0.0f,0.0f, -10.0f);  
        mcam = GetComponent<Camera>();
    }

    // Update is called once per frame
    void Update()
    {
        if (target != null)
        {
            if (target.position.x > 0.0f && target.position.x < 37)
            {
                float dis = target.position.x - transform.position.x;
                dis = Mathf.Abs(dis);

                if (transform.position.x <= 29.3f)
                {
                    if(dis < fluencedis)
                    {
                        transform.position = new Vector3(target.position.x, 0.0f, transform.position.z);
                    }
                    else
                    {
                        transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x, 0, transform.position.z), 2 * Time.deltaTime);
                    }
                }else if(transform.position.x > 29.3f)
                {
                    if(dis < fluencedis)
                    {
                        transform.position = new Vector3(36.57f, 5.2f, transform.position.z);
                        
                    }
                    else
                    {
                        transform.position = Vector3.Lerp(transform.position, new Vector3(36.57f, 5.2f, transform.position.z), 2 * Time.deltaTime);
                        
                    }
                    
                }
                
            }
            else if(target.position.x < 0.0f)
            {
                if(transform.position.x < fluencedis)
                {
                    transform.position = new Vector3(0, 0, transform.position.z);
                }
                else
                {
                    transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x, 0, transform.position.z), 2 * Time.deltaTime);
                }
                
            }
            
        }
    }

    public void BossCamera()
    {
        transform.position = new Vector3(36.57f, 5.2f, transform.position.z);
        if (6f - mcam.fieldOfView < 0.1f)
        {
            mcam.orthographicSize = 6f;
        }
        else
        {
            mcam.orthographicSize = Mathf.Lerp(mcam.fieldOfView, 6f, Time.deltaTime);

        }
    }
}
